import Vue from 'vue';
import { ACCESS_TOKEN } from '@/store/modules/mutation-types'

const user={
    state:{
        token:'',
        name:'',
        welcome:'',
        avatar:'',
        roles:[],
        info:{}
    },

    mutations:{
        SET_TOKEN:(state,token)=>{
            state.token = token;
        },
        SET_NAME:(state,{name,welcome}) => {
            state.name = name;
            state.welcome = welcome;
        }
    },

    actions:{
        Login({commit},userInfo){
            const token = "12345678910";
            Vue.ls.set(ACCESS_TOKEN, token, 7 * 24 * 60 * 60 * 1000);
            commit('SET_TOKEN', token);
            // return new Promise((resolve, reject) => {
            //     login(userInfo).then(response => {
            //         const result = response.result
            //         Vue.ls.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
            //         commit('SET_TOKEN', result.token)
            //         resolve()
            //     }).catch(error => {
            //         reject(error)
            //     })
            // })
        }
    }
}
export default user;